package com.xuliugen;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

import com.xuliugen.image.R;
import com.xuliugen.image.callbackinter.CallbackImageFresh;
import com.xuliugen.image.util.LazyImageLoader;

public class MainActivity extends Activity implements CallbackImageFresh{

	private Button download_btn;
	private Button btn_clean;
	private ImageView imageView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		download_btn = (Button) this.findViewById(R.id.download_btn);
		imageView = (ImageView)this.findViewById(R.id.imageView);
		btn_clean =(Button) this.findViewById(R.id.btn_clean); 
		
		download_btn.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				
				String URL = "http://img.daimg.com/uploads/allimg/150504/3-1505041J142.jpg";
				
				imageView.setTag(URL);
				LazyImageLoader lazyImageLoader = new LazyImageLoader(getApplicationContext(), MainActivity.this);
				
				lazyImageLoader.lazyImgLoader(URL);
			}
		});
		
		btn_clean.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				imageView.setImageResource(R.drawable.ic_launcher);
			}
		});
	}

	/**
	 * 更新UI
	 */
	public void fresh(Object... params) {
		imageView.setImageBitmap((Bitmap) params[0]);
	}
}
